package com.example.coursehub.entity;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import jakarta.persistence.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import java.util.UUID;

@Entity
@Table(name = "favorite_question_bank", schema = "courseHub")
@Getter
@Setter
@NoArgsConstructor
public class FavoriteQuestionBank {

    @Id
    @Column(name = "favorite_question_bank_id", nullable = false, length = 100)
    private String favoriteQuestionBankId;

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @OnDelete(action = OnDeleteAction.CASCADE)
    @JoinColumn(name = "course_id", nullable = false)
    private Course course;

    public FavoriteQuestionBank(String favoriteQuestionBankId, User user, Course course) {
        this.favoriteQuestionBankId = favoriteQuestionBankId == null ? UUID.randomUUID().toString() : favoriteQuestionBankId;
        this.user = user;
        this.course = course;
    }
}
